﻿
module;

#include <string>


export module fast_utils:check_str_utils;

export namespace fast::util {

/**
 * @brief 正则表达式
 */

    class CheckStr {
        enum type {
            phone,
            tel,
            card,
            pwd,
            postal,
            QQ,
            email,
            money,
            URL,
            IP,
            date,
            number,
            english,
            chinese,
            lower,
            upper,
            HTML
        };

        static std::string getType(type type) {
            switch (type) {
                case phone :   //手机号码
                    return R"(^1[3|4|5|6|7|8|9][0-9]{9}$)";
                case tel :     //座机
                    return R"(^(0\d{2,3}-\d{7,8})(-\d{1,4})?$)";
                case card :    //身份证
                    return R"((^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$))";
                case pwd :     //密码以字母开头，长度在6~18之间，只能包含字母、数字和下划线
                    return "^[a-zA-Z]\\w{5,17}$";
                case postal :  //邮政编码
                    return R"([1-9]\d{5}(?!\d))";
                case QQ :      //QQ号
                    return "^[1-9][0-9]{4,9}$";
                case email :   //邮箱
                    return R"(^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$)";
                case money :   //金额(小数点2位)
                    return R"(^\d*(?:\.\d{0,2})?$)";
                case URL :     //网址
                    return R"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)";
                case IP :      //IP
                    return R"(((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d)))";
                case date :    //日期时间
                    return R"(^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || ^(\d{4})\-(\d{2})\-(\d{2})$)";
                case number :  //数字
                    return "^[0-9]$";
                case english : //英文
                    return "^[a-zA-Z]+$";
                case chinese : //中文
                    return R"(^[\\u4E00-\\u9FA5]+$)";
                case lower :   //小写
                    return "^[a-z]+$";
                case upper :   //大写
                    return "^[A-Z]+$";
                case HTML :    //HTML标记
                    return R"(<("[^"]*"|'[^']*'|[^'">])*>)";
                default:
                    return "";
            }
        }

    };//CheckStr
}

